#include <bits/stdc++.h>
//#define int long long
using namespace std;
const int N=1e5+5;
int d[N],v[N],a[N];
int lim,n,m,L;
struct node{
    int l,r;
}nd[N];
bool cmp(node x,node y){
    return x.r<y.r;
}
int p[N];
void solve(){
    cin>>n>>m>>L>>lim;
    for(int i=1;i<=n;i++){
        cin>>d[i]>>v[i]>>a[i];
        if(a[i]>0){
            if(v[i]>lim)nd[i]={d[i],L};
            else if(v[i]==lim)nd[i]={d[i]+1,L};
            else{
                // s=(lim^2-v^2)/2a
                int t=(lim*lim-v[i]*v[i]);
                nd[i]={d[i]+t/(2*a[i])+1,L};
            }
        }
        else if(a[i]==0){
            if(v[i]>lim)nd[i]={d[i],L};
            else nd[i]={L+1,L};
        }
        else{
            if(v[i]<=lim)nd[i]={L+1,L};
            else{
                // s=(v^2-lim^2)/2a
                a[i]=abs(a[i]);
                int t=(v[i]*v[i]-lim*lim);
                int dd=(t-1)/(2*a[i]);
                if(d[i]+dd<=L)nd[i]={d[i],d[i]+dd};
                else nd[i]={d[i],L};
            }
        }
    }
    sort(nd+1,nd+n+1,cmp);
    for(int i=1;i<=m;i++)cin>>p[i];
    int nowr=-1,ans=0,ans2=0;
    for(int i=1;i<=n;i++){
        if(nowr>=nd[i].l){
            ans2++;
            continue;
        }
        int id=upper_bound(p+1,p+m+1,nd[i].r)-p-1;
        if(id>0&&p[id]>=nd[i].l)nowr=p[id],ans++,ans2++;
    }
    cout<<ans2<<' '<<m-ans<<'\n';
}
signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tc;
    cin>>tc;
    while(tc--)solve();
    return 0;
}
